//引入express模块
const express = require("express");
//引入连接池模块
const pool = require("../pool.js");
//console.log(pool)
//创建路由器对象
const router = express.Router();
//通过商品的lid值获取商品信息
//GET /
//地址:http://127.0.0.1:3333/show
//返回结果
router.get("/:lid", (req, res, next) => {
  //定义sql语句]
  let sql = "select * from hbb_list where lid=?";
  //执行数据库操作
  pool.query(sql, [req.params.lid], (err, results) => {
    if (err) {
      next(err);
      return;
    }
    res.send({ code: 200, msg: "获取商品信息成功", data: results });
  });
});
// 查询全部商品
router.get("/", (req, res, next) => {
  pool.query("select * from hbb_list", (err, results) => {
    if (err) {
      next(err);
      return;
    }
    res.send({ code: 201, msg: "获取全部商品", data: results });
  });
});

//暴露路由器对象
module.exports = router;
